/**
 * Created by yanghenga on 2015/8/27.
 */

requirejs.config({
    baseUrl: '../www',
    paths: {
        app: 'js/app',
        component:'js/Components.js',
        ionic: u9.toU9URL('lib/ionic/js/ionic.bundle'),
        microsoftAjax: u9.toU9URL('lib/MicrosoftAjax')
    }
});

// Start the main app logic.
requirejs(['app','microsoftAjax'], function () {
    u9.callSVAlone = function (jsonData) {
        var svFullName = jsonData['name'],
            params = jsonData['params'],
            url = 'http://'+u9.getConnectSetting().address+':'+u9.getConnectSetting().port+'/svc_script/' + '?n=' + svFullName + '&p=null';
        var _onSuccess = null;
        var _onFailure = null;

        var onSuccess = function (data) {
            _onSuccess(data);
        }

        var onFailure = function (data) {
            console.log('call sv error,data is ' + JSON.stringify(data));
            _onFailure(data);
        }
        return require([url], function (bpObj) {
            params.unshift({
                EntCode: u9.getLoginData().EntCode,
                OrgCode: u9.getLoginData().OrgCode,
                UserCode: u9.getLoginData().UserCode,
                CultureName: 'zh-CN'
            });
            if (jsonData['onSuccess']) {
                //params.push(jsonData['onSuccess']);
                _onSuccess = jsonData['onSuccess'];
                params.push(onSuccess);
            } else {
                params.push(onSuccess);
            }
            if (jsonData['onFailure']) {
                _onFailure = jsonData['onFailure'];
                //params.push(jsonData['onFailure']);
                params.push(onFailure);
            } else {
                params.push(onFailure);
            }

            var svcProxy = 'http://'+u9.getConnectSetting().address+':'+u9.getConnectSetting().port+'/u9_gateway/RestServices/' + svFullName + '.svc';
            try {
                bpObj.set_path(svcProxy);
                return bpObj.Do.apply(bpObj, params);
            } catch (e) {
                return jsonData.onFailure(e);
            }
        });
    }
    angular.element(document).ready(function () {
        angular.bootstrap(document, ['starter'])
    })
});